<template>
  <div>
    <div class="form-wrap">
      <input
        v-model="shopZip"
        class="input-block-plain"
        type="number"
        :placeholder="account.shopZip"
        placeholder-class="placeholder-part"
      >
      <button class="btn-round-blue" @click="handleUpdateShopInfo">完成</button>
    </div>
  </div>
</template>

<script>
import {} from '@/utils'
import { UPDATE_SHOP_BASE_INFO } from '@/api'

export default {
  components: {},
  props: {},
  data () {
    return { shopZip: '' }
  },
  computed: {
    account () {
      return this.$store.state.account
    }
  },
  watch: {},
  created () {},
  mounted () {},
  onShow () {},
  methods: {
    handleUpdateShopInfo () {
      if (!this.shopZip) {
        this.$toast('请输入邮编')
      } else {
        this.updateShopInfo()
      }
    },
    updateShopInfo () {
      const vm = this

      let params = {
        shopId: vm.account.shopId,
        shopZip: vm.shopZip
      }

      UPDATE_SHOP_BASE_INFO(params)
        .then(r => {
          if (r.data.code === '0' && r.data.data) {
            vm.$toast('操作成功')
            vm.$store.commit('SET_ACCOUNT_INFO', { shopZip: vm.shopZip })
            vm.shopZip = ''
            vm.$router.go(-1)
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    }
  }
}
</script>
